package com.chen.recruit.controller;

import com.chen.recruit.common.annotation.Log;
import com.chen.recruit.common.api.CommonResult;
import com.chen.recruit.common.enums.BusinessType;
import com.chen.recruit.common.valid.AddGroup;
import com.chen.recruit.common.valid.UpdateGroup;
import com.chen.recruit.domain.College;
import com.chen.recruit.service.CollegeService;
import lombok.RequiredArgsConstructor;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "院系管理 CollegeController")
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/college")
public class CollegeController {

    private final CollegeService collegeService;

    @ApiOperation("新增院系")
    @SaCheckPermission("system:college:add")
    @Log(module = "系统管理-院系管理", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@Validated(AddGroup.class) @RequestBody College college) {
        return collegeService.addOrUpdateCollege(college);
    }

    @ApiOperation("删除院系")
    @SaCheckPermission("system:college:delete")
    @Log(module = "系统管理-院系管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public CommonResult delete(@PathVariable Integer id) {
        return collegeService.deleteCollegeById(id);
    }

    @ApiOperation("更新院系")
    @SaCheckPermission("system:college:update")
    @Log(module = "系统管理-院系管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult update(@Validated(UpdateGroup.class) @RequestBody College college) {
        return collegeService.addOrUpdateCollege(college);
    }

    @ApiOperation("获取院系详细信息")
    @SaCheckPermission("system:college:update")
    @GetMapping("/{id}")
    public CommonResult getInfo(@PathVariable Integer id) {
        return CommonResult.success(collegeService.getById(id));
    }

    @ApiOperation("查询院系列表")
    @SaCheckPermission("system:college:list")
    @GetMapping("/list")
    public CommonResult list(College college) {
        return CommonResult.success(collegeService.getCollegesByCondition(college));
    }

}
